-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix suggestion for removing &mut from &mut macro!(). #85939
Fix suggestion for removing &mut from &mut macro!(). #85939
Conversation
r? @jackh726 (rust-highfive has picked a reviewer for you, use r? to override) |
// E.g. for `&format!("")`, where we want the span to the | ||
// `format!()` invocation instead of its expansion. | ||
if let Some(call_span) = | ||
iter::successors(Some(expr.span), |s| s.parent()).find(|&s| sp.contains(s)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@estebank What do you think about adding this as a function on Span
(e.g. span.find_parent_within(span)
or something)?
I have a feeling more diagnostics can/should use this, but I haven't written enough diagnostics yet to know if that's true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with your assessment and we should have something like that (bikeshed notwithstanding).
src.to_string(), | ||
code, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In another diagnostic, I emitted (potentially multiple) suggestions for removing the parts that need to be removed, instead of a single suggestion that contains a copy of (part of) the original source. Is there a guideline for which to prefer?
Basically:
A. "replace &mut (format!(""))
by format!("")
B. "remove &mut (
and remove )
"
Most diagnostics seem to use A, which surprises me a bit. The suggestion for A can get quite large for large expressions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The later didn't exist until "recently" (2019?), so there's a historical component. There's also a bug that needs to be fixed on rustc's side to allow rustfix apply multipart suggestions, which it can't today.
Even with that caveat, I push for multipart suggestions in all new diagnostics when possible/necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
There's also a bug that needs to be fixed on rustc's side to allow rustfix apply multipart suggestions, which it can't today.
That should be fixed by rust-lang/rustfix#195
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! That should also allow us to add a // run-rustfix
to a bunch of tests that don't have it today because of that 😄
@bors r+, but feel free to change the suggestion to be multipart, if you so desire. |
r? @estebank |
📌 Commit ecebb66 has been approved by |
Rollup of 10 pull requests Successful merges: - rust-lang#83653 (Remove unused code from `rustc_data_structures::sync`) - rust-lang#84466 (rustdoc: Remove `PrimitiveType::{to_url_str, as_str}`) - rust-lang#84880 (Make match in `register_res` easier to read) - rust-lang#84942 (rustdoc: link to stable/beta docs consistently in documentation) - rust-lang#85853 (Warn against boxed DST in `improper_ctypes_definitions` lint) - rust-lang#85939 (Fix suggestion for removing &mut from &mut macro!().) - rust-lang#85966 (wasm: Make simd types passed via indirection again) - rust-lang#85979 (don't suggest unsized indirection in where-clauses) - rust-lang#85983 (Update to semver 1.0.3) - rust-lang#85988 (Note that `ninja = false` goes under `[llvm]`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Fixes #85933
Before: (Note the suggestions.)
After: